package com.gnerv.sylvanas.business.manage.logic;

import com.gnerv.sylvanas.framework.common.model.RestResult;
import com.gnerv.sylvanas.framework.core.BaseUkIdGenerate;
import com.gnerv.sylvanas.business.manage.model.bo.DictItemBO;
import com.gnerv.sylvanas.business.manage.model.dto.DictItemCreateDTO;
import com.gnerv.sylvanas.business.manage.model.dto.DictItemUpdateDTO;
import com.gnerv.sylvanas.business.manage.model.vo.DictItemVO;
import com.gnerv.sylvanas.business.manage.operation.DictItemOperationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class DictItemLogicService  {

    private final DictItemOperationService dictItemOperationService;
    private final BaseUkIdGenerate baseUkIdGenerate;

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> create(DictItemCreateDTO dictItemCreateDTO) {
        DictItemBO dictItemBO = dictItemCreateDTO.toDictItemBO();
        dictItemBO.setUkId(baseUkIdGenerate.generate());
        dictItemOperationService.create(dictItemBO);
        return RestResult.ok();
    }

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> deleteByUkId(String ukId) {
        dictItemOperationService.deleteByUkId(ukId);
        return RestResult.ok();
    }

    
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> updateByUkId(DictItemUpdateDTO dictItemUpdateDTO) {
        dictItemOperationService.updateByUkId(dictItemUpdateDTO.toDictItemBO());
        return RestResult.ok();
    }

    
    public RestResult<DictItemVO> selectVOByUkId(String ukId) {
        return RestResult.ok(dictItemOperationService.selectVOByUkId(ukId));
    }

    
    public RestResult<List<DictItemVO>> selectListVOByDictUkId(String dictUkId) {
        return RestResult.ok(dictItemOperationService.selectListVOByDictUkId(dictUkId));
    }

}
